<?php

class AccountController extends Zend_Controller_Action {

    protected $_redirector = null;

    public function init() {
        /* Initialize action controller here */
    }

    public function indexAction() {
        if(SessionServices::HasSessionStarted()) {
           $this->_redirector = $this->_helper->getHelper('Redirector');
           $this->_redirector->gotoUrl('/dashboard');
        }
    }

    public function logindoAction() {  
        $request = $this->getRequest();
        if (!$request->isPost()) {
            return $this->_helper->redirector('index');
        }

        $email = $this->_getParam('userName');
        $password = $this->_getParam('userPwd');

        if(isset($email) && isset($password)) {
            $id = AccountServices::Authenticate($email, $password);
            if($id > 0) {
                SessionServices::StartSession($id);
                $this->_helper->redirector('index');
            } else {
                echo "error here";
                exit;
            }
        }
    }

    public function logoutdoAction(){
        SessionServices::TerminateSession();
        $this->_helper->redirector('index');
    }

}

?>
